package com.zdx.yswl.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.loopj.android.image.SmartImageView;
import com.zdx.yswl.R;
import com.zdx.yswl.tool.KNetTool;
import com.zdx.yswl.tool.KSystemTool;
import com.zdx.yswl.ui.bean.ConsultantBean;
import com.zdx.yswl.view.listview.BaseListViewAdapter;

public class ConsultantAdapter extends BaseListViewAdapter<ConsultantBean> {
	
	private OnClickListener mPraiseClickListstener;
	
	public ConsultantAdapter(Context _context, OnClickListener mPraiseClickListstener) {
		super(_context);
		this.mPraiseClickListstener  = mPraiseClickListstener;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(this.context).inflate(R.layout.activity_consultant_list_item, null);
			viewHolder = new ViewHolder();
			viewHolder.head = (SmartImageView) convertView.findViewById(R.id.contacts_head_img);
			viewHolder.name = (TextView) convertView.findViewById(R.id.contacts_name_tv);
			viewHolder.zanBtn = (Button) convertView.findViewById(R.id.contacts_zan_btn);
			viewHolder.callBtn = (Button) convertView.findViewById(R.id.contacts_call_btn);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		final ConsultantBean bean = this.getItem(position);
		
		if (KNetTool.isNetworkAvalible(context)) {
			viewHolder.head.setImageUrl(bean.headUrl);
		}else{
			viewHolder.head.setImageResource(R.drawable.aio_image_fail_round);
		}
		viewHolder.name.setText(bean.name);
		viewHolder.zanBtn.setTag(position);
		viewHolder.callBtn.setTag(position);
		if (bean.goodCount > 0) {
			viewHolder.zanBtn.setBackgroundResource(R.drawable.goodbutton_selector_two);
			viewHolder.zanBtn.setText(bean.goodCount+"");
		}
		viewHolder.zanBtn.setOnClickListener(mPraiseClickListstener);
		viewHolder.callBtn.setOnClickListener(mPraiseClickListstener);
		return convertView;
	}
	
	private static class ViewHolder {
		public SmartImageView head;
		public TextView name;
		public Button zanBtn;
		public Button callBtn;
	}

}
